package com.jt.web.controller;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jt.pojo.ItemDesc;
import com.jt.util.ObjectMapperUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
@RestController
public class JSONPController {

//    @RequestMapping("/web/testJSONP")
//    public JSONPObject jsonp(String callback){
//        ItemDesc itemDesc=new ItemDesc();
//        itemDesc.setItemId(1000L).setItemDesc("JSONP调用成功")
//                .setCreated(new Date()).setUpdated(new Date());
//        JSONPObject jsonpObject=new JSONPObject(callback, itemDesc);
//        return jsonpObject;
//    }



    @RequestMapping("/web/testJSONP")
    public String jsonp(String callback){
        ItemDesc itemDesc=new ItemDesc();
        itemDesc.setItemId(1000L).setItemDesc("JSONP调用成功")
                .setCreated(new Date()).setUpdated(new Date());
        String json= ObjectMapperUtil.toJSON(itemDesc);
        return callback+"("+json+")";
    }
}
